package com.yc.controller;

import cn.hutool.core.lang.Snowflake;
import com.yc.web.bean.ResponseResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ID生成控制器
 * 提供高并发ID生成接口
 */
@Tag( name="generate Id",description = "雪花算法生成Id")
@RestController
@RequestMapping()
@Slf4j
public class IdGeneratorController {

    // 注入Snowflake ID生成器
    @Autowired
    private Snowflake snowflake;

    /**
     * 生成分布式ID
     */

    @GetMapping ("/generate")// 处理GET请求
    public ResponseResult generateId() {
        // 生成Snowflake ID
        long id = snowflake.nextId();
        // 返回统一格式的成功响应，并设置生成的ID
        return ResponseResult.ok().setData(String.valueOf(id));
    }
}